package com.zyz.system.manager;

import com.zyz.common.core.constants.CacheConstants;
import com.zyz.common.redis.service.RedisService;
import com.zyz.system.model.exam.Exam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class ExamCacheManager {

    @Autowired
    private RedisService redisService;

    public void addCache(Exam exam) {
        redisService.leftPushForList(getExamListKey(), exam.getExamId());
        redisService.setCacheObject(getDetailKey(exam.getExamId()), exam);
    }

    public void deleteCache(Exam exam) {
        redisService.deleteObject(getDetailKey(exam.getExamId()));
        redisService.deleteObject(getExamListKey());
        redisService.deleteObject(getExamQuestionListKey(exam.getExamId()));
    }


    private String getExamListKey () {
        return CacheConstants.EXAM_UNFINISHED_LIST; // 未完赛列表key
    }

    private String getDetailKey (Long examId) {
        return CacheConstants.EXAM_DETAIL + examId; // 竞赛详情
    }

    private String getExamQuestionListKey(Long examId) {
        return CacheConstants.EXAM_QUESTION_LIST + examId;
    }


}
